(function(jQuery){
	$.flySearch=function(){
        this.defaultInit = function(){
            this.eventsBing();
        }
		    /**
         * 查询方式切换改变样式及状态赋值
         * @param {Object} obj
         */
        this.changeClor=function(obj){
            if (obj== "flight1") {
                $$("flight1").className = "ub-f1 uinn  bc16 t-wh  tx-c";
                $$("flight2").className = "ub-f1 uinn  tx-c";
                $("#xians").text("航班号")
                $("#flight").attr('placeholder', '请输入航班号 如：5677')
                $$("filghtHX").className = "uhide  ulab";
                $$("filghtNo").className = "ub  ulab";
                $$("flightNoUpload").className = "btn uba b-org uinn c-org  t-wh  tx-c ub ub-ac ub-pc";
                $$("hxNoUpload").className = "uhide";
                
            }
            else {
                $$("flight1").className = "ub-f1 uinn tx-c";
                $$("flight2").className = "ub-f1 uinn  bc16 t-wh  tx-c";
                $$("filghtHX").className = "ub  ulab";
                $$("filghtNo").className = "uhide  ulab";
                $$("hxNoUpload").className = "btn uba b-org uinn c-org  t-wh  tx-c ub ub-ac ub-pc";
                $$("flightNoUpload").className = "uhide";
            }
        }
        
        /**
         * 查询提交
         * @param {Object} type
         */
        this.showFlightNo = function(type){
            var dataTime = $("#startDate").text();//获取时间段
            setStorage("dateTime", dataTime);
            if(type==0){
				 var flight = $$("flight").value;
            if (!flight) {
                uexWindow.alert("提示消息", "请输入查询航班", "确定");
                return;
            }
            var data = {
                "time": dataTime,
                "flightNo": flight
            };
			setStorage("data",JSON.stringify(data));  
            iG.openWin("flyList_win", data);
			}else{
            var data = {
                "time": dataTime,
                "deptAirport": $("#qifei1").text(),
				"arrAirport": $("#jiangluo1").text(),
            };
			setStorage("data",JSON.stringify(data));  
            iG.openWin("flyList_win", data);
			}
        }
        
        /**
         * 获取机场列表
         */
        this.getCity = function(no){
            uexWindow.evaluateScript('', '0', 'changeTop(1)');
            var path = "jgp/res/citys.png";//保存城市列表信息的文件路径
            var DHcity = 0;//城市列表窗体状态标识（打开OR关闭）
            var s = window.getComputedStyle(document.body, null);
            var headerHeight = getStorage('headerHeight');
            uexDHCity.open(0, headerHeight, int(s.width), int(s.height), path, '输入要查找的城市名或三字码', '热门城市');
            uexDHCity.cbSelected = function(opId, dataType, data){
                setStorage('saveSelCity', data);//保存选中的城市信息
                //延时关闭城市列表窗体
                setTimeout(function(){
                    uexDHCity.close();
                    DHcity = 0;
                    $.flySearch().setCity(no);
                }, 200);
            }
            DHcity = 1;
        }
        
		/**
		 * 关闭机场列表插件
		 */
        this.closeWin = function(){
            uexDHCity.close();
        }
        
        //获取选择 的城市
        this.setCity = function(type){
            uexWindow.evaluateScript('', '0', 'changeTop(3)');
            var city = JSON.parse(getStorage('saveSelCity'));
            var cityName = (city.name).substring(4, (city.name).length);
            if (type == 1) {
                $("#qifei").text(cityName);//保存选中的城市信息
                $("#qifei1").text(city.code);//保存选中的城市信息
            }
            else {
                $("#jiangluo").text(cityName);//保存选中的城市信息
                $("#jiangluo1").text(city.code);//保存选中的城市信息
            }
        }
        
        //起降城市及三字码进行数据切换
        this.jiaohuan = function(){
            var city = '',city1 = '';
            city = $("#qifei").text();
            $("#qifei").text($("#jiangluo").text());
            $("#jiangluo").text(city);
            city1 = $("#qifei1").text();
            $("#qifei1").text($("#jiangluo1").text());
            $("#jiangluo1").text(city1);
        }
		
            //所有事件我们可以在这里绑定
		 this.eventsBing = function () {
            $("#flight1").on('click', function () {
                $.flySearch().changeClor('flight1');
            });
			 $("#flight2").on('click', function () {
                $.flySearch().changeClor('flight2');
            });
			 $(".taking").on('click', function () {
                $.flySearch().getCity(1);
            });
			 $(".landing").on('click', function () {
                $.flySearch().getCity(2);
            });
			 $(".jh").on('click', function () {
                $.flySearch().jiaohuan();
            });
			$("#flightNoUpload").on('click', function () {
                $.flySearch().showFlightNo(0);
            });
			$("#hxNoUpload").on('click', function () {
                $.flySearch().showFlightNo(1);
            });
        };
		
		 this.load = function(isRefresh){
                isRefresh || $.iBoxWait();
                var data = JSON.parse(getStorage("data"));
                $.ajax({
                    //提交数据的类型 POST GET
                    type: "POST",
                    //提交的网址
                    url: queryUrl+"bytime",
                    //提交的数据
                    data: data,
                    //返回数据的格式
                    datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                    //成功返回之后调用的函数             
                    success: function(json){
						//json = json.replace(/null/g,'""');
                        var data=JSON.parse(json);	
                        iG.ajaxCallback(isRefresh);
                        $("#msg").addClass("uhide");
                            if (data.status == 1) {
                                $.iBoxMsg("请求失败");
                                return;
                            };
                            if ((data.array == "" || data.array == null)) {
                                $("#list>li").not(".uhide").remove();
                                $("#msg").removeClass("uhide");
                                return;
                            };
							setStorage("properties",JSON.stringify(data.properties));		
                            $("#list>li").not(".uhide").remove();
                            flyList.append(data.array);
                    },
                    //调用出错执行的函数
                    error: function(err){
                        //请求出错处理
                        $.iBoxMsg("网络异常");
                    }
                });
            };
		return this;
	}
})(jQuery);